package cn.mymanagesys.service.impl;

import cn.mymanagesys.dao.SysMenuDao;
import cn.mymanagesys.dao.impl.SysMenuDaoImpl;
import cn.mymanagesys.entity.SysMenu;
import cn.mymanagesys.service.SysMenuService;

import java.util.ArrayList;
import java.util.List;

public class SysMenuServiceImpl implements SysMenuService {

    private SysMenuDao sysMenuDao = new SysMenuDaoImpl();

    @Override
    public List<SysMenu> menusTree() {
        List<SysMenu> list = new ArrayList<>();

        // 根菜单
        list = sysMenuDao.selectByParentId(0);

        for (SysMenu sysMenu:list){
            // 系统管理
            List<SysMenu> child = sysMenuDao.selectByParentId(sysMenu.getMenuId().intValue());
            sysMenu.getChildren().addAll(child);
        }
        return list;
    }
}
